//
//  MTPublishActionView.m
//  MeToo
//
//  Created by 俊松何 on 2018/7/3.
//  Copyright © 2018年 tianxie. All rights reserved.
//

#import "MTPublishActionView.h"
#import "MTVerticalButton.h"



@interface MTPublishActionView ()

@property(nonatomic,strong) MTVerticalButton *liveButton;
@property(nonatomic,strong) MTVerticalButton *topicButton;
@property(nonatomic,strong) MTVerticalButton *videoButton;

@property(nonatomic,strong) UIButton *closeButton;
@property(nonatomic,strong) KLCPopup *pop;


@end


@implementation MTPublishActionView


+(MTPublishActionView *)publishActionView
{
    MTPublishActionView *publishActionView = [[MTPublishActionView  alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 250)];
    return publishActionView;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor whiteColor];
        [self makeUI];
    }
    return self;
}

-(void)makeUI
{
    _liveButton = [[MTVerticalButton alloc] initWithFrame:CGRectMake(0, 0, 80, 100)];
    _topicButton = [[MTVerticalButton alloc] initWithFrame:CGRectMake(0, 0, 80, 100)];
    _videoButton = [[MTVerticalButton alloc] initWithFrame:CGRectMake(0, 0, 80, 100)];
    
    _closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    
    _liveButton.tag = 1;
    _topicButton.tag = 2;
    _videoButton.tag = 3;
    
    [_liveButton setTitleColor:UIColorFromRGB(0x838d8a) forState:UIControlStateNormal];
    [_topicButton setTitleColor:UIColorFromRGB(0x838d8a) forState:UIControlStateNormal];
    [_videoButton setTitleColor:UIColorFromRGB(0x838d8a) forState:UIControlStateNormal];

    [_liveButton setImage:[UIImage imageNamed:@"live"] forState:UIControlStateNormal];
    [_liveButton setTitle:@"直播" forState:UIControlStateNormal];
    
    [_topicButton setImage:[UIImage imageNamed:@"photograph"] forState:UIControlStateNormal];
    [_topicButton setTitle:@"图片" forState:UIControlStateNormal];

    [_videoButton setImage:[UIImage imageNamed:@"video"] forState:UIControlStateNormal];
    [_videoButton setTitle:@"视频" forState:UIControlStateNormal];

    [_videoButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_topicButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_liveButton addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_closeButton setImage:[UIImage imageNamed:@"publishClose"] forState:UIControlStateNormal];
    [_closeButton addTarget:self action:@selector(dismis) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:_liveButton];
//    [self addSubview:_topicButton];
//    [self addSubview:_videoButton];
    [self addSubview:_closeButton];

//    [_liveButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(@(70));
//        make.height.mas_equalTo(@(100));
//        make.centerX.mas_equalTo(self.mas_centerX).offset(-120);
//        make.centerY.mas_equalTo(self.mas_centerY).offset(-10);
//    }];
    
    [_liveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@(70));
        make.height.mas_equalTo(@(100));
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.mas_centerY).offset(-10);
    }];
//
//    [_videoButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_equalTo(@(70));
//        make.height.mas_equalTo(@(100));
//        make.centerX.mas_equalTo(self.mas_centerX).offset(120);
//        make.centerY.mas_equalTo(self.mas_centerY).offset(-10);
//    }];
    
    [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@(40));
        make.height.mas_equalTo(@(40));
        make.centerX.mas_equalTo(self.mas_centerX).offset(0);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-34);
    }];
}


-(void)show
{
    KLCPopup *newpop = [KLCPopup popupWithContentView:self];
    newpop.showType = KLCPopupShowTypeSlideInFromBottom;
    newpop.dismissType = KLCPopupDismissTypeSlideOutToBottom;
    newpop.maskType = KLCPopupMaskTypeDimmed;
    self.pop = newpop;
    [newpop showAtCenter:CGPointMake(WIDTH/2.0, HEIGHT - self.frame.size.height/2) inView:[[UIApplication sharedApplication].delegate window]];
    
    POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    anim.fromValue = @(300);
    anim.toValue = @(100);
    anim.springBounciness = 1;
    [self.liveButton.layer pop_addAnimation:anim forKey:@"positionY"];
    
    POPSpringAnimation *anim2 = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    anim2.fromValue = @(300);
    anim2.toValue = @(100);
    [self.topicButton.layer pop_addAnimation:anim2 forKey:@"positionY"];
    
    POPSpringAnimation *anim3 = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    anim3.fromValue = @(300);
    anim3.toValue = @(100);
    [self.videoButton.layer pop_addAnimation:anim2 forKey:@"positionY"];
}

-(void)dismis
{
    [self.pop dismiss:YES];
}

-(void)btnClick:(UIButton *)btn
{
    [self dismis];
    if (self.deleagte && [self.deleagte respondsToSelector:@selector(buttonClick:)])
    {
        [self.deleagte buttonClick:btn.tag];
    }
    
}




@end
